package com.hieu.sms.utils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public final class ClassFieldNameUtils {

    public static String[] getFieldNames(String className) {
	List<String> filedNames = null;
	try {
	    Class<?> cl = Class.forName(className);
	    Field fields[] = cl.getDeclaredFields();
	    if (fields != null) {
		int numField = fields.length;
		filedNames = new ArrayList<String>();
		for (int i = 0; i < numField; i++) {
		    if (!(fields[i].getName().equals("serialVersionUID") || fields[i]
			    .getType().getName().equals("java.util.List"))) {
			filedNames.add(fields[i].getName());
		    }
		}
	    }

	} catch (ClassNotFoundException e) {
	    e.printStackTrace();
	}

	if (filedNames != null) {
	    return filedNames.toArray(new String[filedNames.size()]);
	} else {
	    return null;
	}

    }

    public static String[] getFieldNames(Class<?> cl) {
	return getFieldNames(cl.getName());
    }

    public static void main(String agr[]) {
	/*
	 * String fields[] = getFieldNames(TransactionRequestMessage.class); if
	 * (fields != null) { for (int i = 0; i < fields.length; i++) {
	 * System.out.println(fields[i]); } } TransactionRequestMessage message
	 * = new TransactionRequestMessage(); message.setVersion("1.0.0");
	 * message.setCharset("UTF-8"); message.setTransType("01"); for(String
	 * field :UpopPaymentConfigure.reqVo){ String value =
	 * BeanUtilities.getProperty(message, field, "");
	 * System.out.println(field+"="+value); } Object valueObject = new
	 * String("10000"); BeanUtilities.setProperty(message,
	 * UpopPaymentConfigure.reqVo[15],valueObject);
	 * 
	 * Object value = BeanUtilities.getProperty(message,
	 * UpopPaymentConfigure.reqVo[15], "");
	 * System.out.println(UpopPaymentConfigure.reqVo[15]+"="+value);
	 */
    }
}
